<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/25
 * Time: 15:18
 */
namespace app\admin\controller;
use JPush\Client as JPush;
class JpushController {



    //极光推送appkey
    static public function app_key(){

        $app_key = "cddcbafa872a795e81745e6b";
        return $app_key;
    }
    //极光推送master_secret
    static public function master_secret(){

        $master_secret = "367ec38e57a5477e541794fc";
        return $master_secret;
    }
    //获取alias和tags
    public function getDevices($registrationID){


        $app_key = $this->app_key();
        $master_secret = $this->master_secret();

        $client = new JPush($app_key, $master_secret);

        $result = $client->device()->getDevices($registrationID);

        return $result;

    }
    //添加tags
    public function addTags($registrationID,$tags){



        $app_key = $this->app_key();
        $master_secret = $this->master_secret();

        $client = new JPush($app_key, $master_secret);

        $result = $client->device()->addTags($registrationID,$tags);

        return $result;

    }

    //移除tags
    public function removeTags($registrationID,$tags){


        $app_key = $this->app_key();
        $master_secret = $this->master_secret();

        $client = new JPush($app_key, $master_secret);

        $result = $client->device()->removeTags($registrationID,$tags);

        return $result;

    }
    //标签推送
    public function push($tag,$alert){



        $app_key = $this->app_key();
        $master_secret = $this->master_secret();

        $client = new JPush($app_key, $master_secret);

        $tags = implode(",",$tag);

        $client->push()
            ->setPlatform(array('ios', 'android'))
            ->addTag($tags)                          //标签
            ->setNotificationAlert($alert)           //内容
            ->send();

    }

    //别名推送
    public function push_a($alias,$alert){



        $app_key = $this->app_key();
        $master_secret = $this->master_secret();

        $client = new JPush($app_key, $master_secret);

        $alias = implode(",",$alias);

        $client->push()
            ->setPlatform(array('ios', 'android'))
            ->addAlias($alias)                      //别名
            ->setNotificationAlert($alert)          //内容
            ->send();

    }

//全部推送
    public function push_all($alert)
    {
//        require_once EXTEND_PATH . 'JPush/autoload.php';

        $app_key = $this->app_key();
        $master_secret = $this->master_secret();

        $client = new JPush($app_key, $master_secret);

        $client->push()
            ->setPlatform('all')
            ->addAllAudience()
            ->setNotificationAlert($alert)
            ->send();


    }


}